#include "../../muduo/tcp_server.hpp"

void OnConnected(const Muduo::Connection::PtrConnection & conn)
{
    DLOG("new connection:%p",conn.get());
}

void OnClosed(const Muduo::Connection::PtrConnection & conn)
{
    DLOG("close connection:%p",conn.get());
}

void OnMessage(const Muduo::Connection::PtrConnection & conn,Muduo::Buffer * buf)
{
    DLOG("%s",buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "hello world";
    conn->Send(str.c_str(),str.size());
    // conn->Shutdown();
}

int main()
{
    Muduo::TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}